package com.capgemini.teamtwo.controller;

import com.capgemini.teamtwo.common.ResponseBean;
import com.capgemini.teamtwo.entity.PageRequest;
import com.capgemini.teamtwo.entity.PageResult;
import com.capgemini.teamtwo.entity.dto.ProjectMemberDTO;
import com.capgemini.teamtwo.service.ProjectMemberService;
import io.swagger.annotations.ApiModel;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiModel("项目成员")
@RestController
@RequestMapping("member")
@RequiredArgsConstructor
public class ProjectMemberController {

    private final ProjectMemberService memberService;


    /**
     * 查询在项目上用户列表
     * @param request 分页条件
     * @return 分页结果
     */
    @PostMapping("/findProjectUsers")
    public ResponseBean findProjectUsers(@RequestBody PageRequest<ProjectMemberDTO> request){
        return ResponseBean.success(memberService.findProjectUsers(request));
    }

    /**
     * 释放用户
     * @param dto
     * @return
     */
    @PostMapping("/release")
    public ResponseBean release(@RequestBody ProjectMemberDTO dto){
        return ResponseBean.success(memberService.releaseById(dto));
    }


    /**
     * 查询bench状态用户列表
     * @param request 分页条件
     * @return 分页结果
     */
    @PostMapping("/findBenchUsersByUsername")
    public ResponseBean<PageResult> findBenchUsersByUsername(@RequestBody PageRequest<String> request){
        return ResponseBean.success(memberService.findByUsername(request));
    }


    /**
     * 新增用户
     * @param dto
     * @return
     */
    @PostMapping("/addBatch")
    public ResponseBean addBatch(@RequestBody ProjectMemberDTO dto){
        return ResponseBean.success(memberService.addBatch(dto));
    }
}
